/*
 * SteepTimer - A timer designed for tea fanatics
 * Copyright (C) 2011  Wesley Crossman
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#include "TeaTimerEditDialog.h"
#include "ui_TeaTimerEditDialog.h"

TeaTimerEditDialog::TeaTimerEditDialog(QWidget *parent, const QTime &startTime) :
            QDialog(parent),
            m_ui(new Ui::TeaTimerEditDialog),
            m_return(Cancel) {
    m_ui->setupUi(this);
    m_ui->timTimer->setTime(startTime);
    if (startTime.isNull()) {
        setWindowTitle(tr("New Timer"));
        m_ui->btnDelete->setEnabled(false);
    }
    updateUi();
    connect( m_ui->timTimer, SIGNAL(validityChanged(bool)), SLOT(updateUi()) );
}

TeaTimerEditDialog::~TeaTimerEditDialog() {
    delete m_ui;
}

QTime TeaTimerEditDialog::getTime() {
    return m_ui->timTimer->getTime();
}

void TeaTimerEditDialog::updateUi() {
    bool zeroed = getTime().isNull();
    m_ui->btnSave->setEnabled(!zeroed);
    m_ui->btnRun->setEnabled(!zeroed);
}

void TeaTimerEditDialog::on_btnSave_clicked() {
    m_return = Save;
    accept();
}

void TeaTimerEditDialog::on_btnRun_clicked() {
    m_return = Run;
    accept();
}

void TeaTimerEditDialog::on_btnDelete_clicked() {
    m_return = Delete;
    accept();
}
